package com.yidu.t279;

import com.yidu.t279.dao.UserDao;
import com.yidu.t279.pojo.User;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：liandyao
 * @description：TODO
 * @date ：2020/4/22 14:12
 */
public class UserTest {

    @Test
    public void findById(){
        SqlSession session = App.getSqlSession();

        User rows = session.selectOne("com.yidu.t279.pojo.User.selectById",1);

        System.out.println("操作成功"+rows);



        session.close();
    }


    @Test
    public void findAll(){
        SqlSession session = App.getSqlSession();

        User user = new User();
        user.setUserName("张三");
        //user.setUserAccount("zs");

        user.setRemark("懒");

        List rows = session.selectList("com.yidu.t279.pojo.User.selectAll",user);

        System.out.println("操作成功"+rows);



        session.close();
    }

    @Test
    public void deleteAll(){
        SqlSession session = App.getSqlSession();

        int[] arr = {26,27,28,29};

        int rows = session.delete("com.yidu.t279.pojo.User.deleteAll",arr);

        System.out.println("共删除"+rows);

        session.close();
    }

    @Test
    public void selectAllIds(){
        SqlSession session = App.getSqlSession();

        List<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        list.add(6);
        list.add(7);


        List<User> listUser = session.selectList("com.yidu.t279.pojo.User.selectByIds",list);

        for (User user:listUser) {
            System.out.println(user.getUserName());
        }

        session.close();
    }


    @Test
    public void selectAll(){
        SqlSession session = App.getSqlSession();

        UserDao userdao = session.getMapper(UserDao.class);
        User user = new User();
        user.setUserName("张三");
        //user.setUserAccount("zs");

        user.setRemark("懒");

        List<User> list = userdao.selectAll(user);

        for(User po:list){
            System.out.println(po.getUserName());
        }

    }



}
